<template>
  <div class="demo">
    <h1>学校名称:{{ name }}</h1>
    <h1>学校地址:{{ address }}</h1>
    <h1>学生姓名:{{ studentName }}</h1>
    <button @click="deletSchool">点击销毁</button>
  </div>
</template>
<script>
import pubsub from "pubsub-js";
export default {
  name: "School",
  data() {
    return {
      name: "B站大学",
      address: "家里蹲",
      studentName: "",
    };
  },
  methods: {
    deletSchool() {
      this.$destroy();
    },
  },
  mounted() {
    this.pubId = pubsub.subscribe("getStudentName", (msgName, data) => {
      console.log("我是School组件我收到了我订阅的getStudentName消息", data);
      this.studentName = data;
    });
  },

  beforeDestroy() {
    pubsub.unsubscribe(this.pubId);
  },
};
</script>

<style scoped>
.demo {
  background-color: blueviolet;
}
</style>